import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

/**
 * @Title: 小白月赛88A
 * @Author 贾金博
 * @Package PACKAGE_NAME
 * @Date 2024/3/13 18:09
 * @description:
 */
public class 小白月赛88A {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int x = sc.nextInt();
        int n = sc.nextInt();
        ty[] a = new ty[n];
        for(int i = 0; i < n; ++ i) {
            ty t = new ty(sc.next().charAt(0), sc.nextInt());
            a[i] = t;
        }
        Arrays.sort(a, new Comparator<ty>() {
            @Override
            public int compare(ty o1, ty o2) {
                return o2.getValue() - o1.getValue();
            }
        });

        if(1000 * a[0].getValue() < x) {
            System.out.println(-1);
            return;
        }
        for(int i = 1; i <= 1000; ++ i) {
            System.out.print(a[0].getKey());
        }

    }
}
class ty {
    private char key;
    private int value;

    public ty() {
    }

    public ty(char key, int value) {
        this.key = key;
        this.value = value;
    }

    /**
     * 获取
     * @return key
     */
    public char getKey() {
        return key;
    }

    /**
     * 设置
     * @param key
     */
    public void setKey(char key) {
        this.key = key;
    }

    /**
     * 获取
     * @return value
     */
    public int getValue() {
        return value;
    }

    /**
     * 设置
     * @param value
     */
    public void setValue(int value) {
        this.value = value;
    }

    public String toString() {
        return "ty{key = " + key + ", value = " + value + "}";
    }
}
